package com.qfedu.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qfedu.dao.SysOrderMapper;
import com.qfedu.pojo.SysOrder;
import com.qfedu.service.SysOrderService;
import com.qfedu.service.SysUserService;
import com.qfedu.vo.VOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.UsesSunMisc;
import org.springframework.stereotype.Service;
import sun.font.EAttribute;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

//@Service 相当于实例化SysOrderServiceImpl
@Service
public class SysOrderServiceImpl implements SysOrderService {
    @Autowired//根据类型自动注入
    private SysOrderMapper orderDao;

    //查询所有订单
    @Override
    public Map<String, Object> selectAllV(Integer uid, int page) {
        PageHelper.startPage(page, 5);
        List<VOrder> list = orderDao.selectAll(uid);

        Map<String, Object> map = new HashMap<>();
        map.put("total", ((Page) list).getTotal());
        map.put("rows", list);
        return map;
    }

    //删除订单
    @Override
    public void deleteOrder(Integer id) {
        try {
            orderDao.deleteByPrimaryKey(id);
        } catch (Exception e) {
            throw new RuntimeException("success!");
        }
    }

    //提交订单
    @Override
    public void addOrder(Integer uid, Integer cid, Integer getid, Integer backid, String oprices) {
        String status = "已预订";

        double oprice = Double.parseDouble(oprices);
        SysOrder order = new SysOrder();
        order.setUid(uid);
        order.setCid(cid);
        order.setGetid(getid);
        order.setBackid(backid);
        order.setOprice(oprice);
        order.setStatus(status);
        orderDao.insertSelective(order);
    }
}